package com.example.myapplication3.home;

import android.content.Intent;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;

import com.example.myapplication3.R;
import com.example.myapplication3.base.BaseActivity;
import com.example.myapplication3.image.ImageActivity;
import com.example.myapplication3.video.VideoActivity;


public class HomeActivity extends BaseActivity {

    @Override
    public int getLayoutMain() {
        return R.layout.activity_home;
    }

    @Override
    public void initData() {

    }

    private CardView cardView_image;
    private CardView cardView_app;
    private CardView cardView_audio;
    private CardView cardView_vodio;
    private CardView cardView_doc;

    @Override
    public void initView() {
        setSupportActionBar(findViewById(R.id.toolbar));
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        cardView_image = findViewById(R.id.card_1_1);
        cardView_vodio = findViewById(R.id.card_1_2);
        cardView_audio = findViewById(R.id.card_2_1);
        cardView_app = findViewById(R.id.card_2_2);
        cardView_doc = findViewById(R.id.card_3_1);
    }

    @Override
    public void initListener() {
        cardView_image.setOnClickListener(clickListener);
        cardView_vodio.setOnClickListener(clickListener);
        cardView_audio.setOnClickListener(clickListener);
        cardView_app.setOnClickListener(clickListener);
        cardView_doc.setOnClickListener(clickListener);
    }

    private View.OnClickListener clickListener = v -> {
        Intent intent = new Intent();
        if (v.getId() == R.id.card_1_1) {
            intent.setClass(HomeActivity.this, ImageActivity.class);
            startActivity(intent);
        }
        if (v.getId() == R.id.card_1_2) {
            intent.setClass(HomeActivity.this, VideoActivity.class);
            startActivity(intent);
        }
        if (v.getId() == R.id.card_2_1) {
            Toast.makeText(this, "2-1", Toast.LENGTH_SHORT).show();
        }
        if (v.getId() == R.id.card_2_2) {
            Toast.makeText(this, "2-2", Toast.LENGTH_SHORT).show();
        }
        if (v.getId() == R.id.card_3_1) {
            Toast.makeText(this, "3-1", Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId()==android.R.id.home){
            finish();
        }
        return super.onOptionsItemSelected(item);
    }
}